import { _decorator, Component, director, Layers, Node, resources, Sprite, SpriteFrame, UITransform } from "cc"
const { ccclass, property } = _decorator
import ResourceManager from "../../Runtime/ResourceManager"
import { TileManager } from "./TileManager"
import { createUINode } from "../../Utils/TileManager"
import { DataManagerInstance } from "../../Runtime/DataManager"

@ccclass("TileMapManager")
export class TileMapManager extends Component {
  async initMap() {
    const { mapInfo } = DataManagerInstance

    const imgs = await ResourceManager.loadRes("texture/tile/tile")

    mapInfo.forEach((item1, index1) => {
      item1.forEach((item2, index2) => {
        if (item2.src && item2.type) {
          const img = imgs.find(item => item.name == `tile (${item2.src})`)
          const node = createUINode()

          const tileManager = node.addComponent(TileManager)
          tileManager.init(img, index1, index2)

          node.layer = 1 << Layers.nameToLayer("UI_2D")
          node.setParent(this.node)
        }
      })
    })
  }

  update(deltaTime: number) {}
}
